package dummy.virussim

import mars.ns.TurnSimulation
import mars.ns.core._
import mars.ns.selectors.RandomSelection
import mars.ns.visualisation.VisualisationListener
import mars.ns.Simulation
import mars.ns.selectors.DepthFirstSelection
import mars.ns.selectors.DepthFirstSelection
import mars.ns.statechangers.ConnectedStateChange

object TurnSim extends Application{        
	/**
	 * Function that determines if there are still people left that are healthy
	 */
	def stillHealthyLeftFunction(network : Network[Person]) : Int => Boolean = {
    		return ((_ : Int) => (!(network.getNodes() exists ((person : Person) => person.isHealthy ))));
    }
	
    val net:Network[Person] = new Network[Person]()
    
    for(i<-0 until 50){
        net.addNode(new Person)
    }
    val infectedPerson = new Person
    infectedPerson.setInfected
    infectedPerson.addDoubleLink(net.getNodes().apply(5))
    net.addNode(infectedPerson)
    // Simulation that stops when all nodes are connected
//    val sim: TurnSimulation[Person] = new TurnSimulation(net, Simulation.allConnectedFunction[Person](net)) with RandomSelection[Person] with InfectedStateChange[Person]
    
    // Simulation that stops when there are no healthy people left
    val sim: TurnSimulation[Person] = new TurnSimulation(net, Simulation.allConnectedFunction[Person](net)) with RandomSelection[Person] with ConnectedStateChange[Person]
    sim.subscribe(new VirusVisualisation[Person](net))
    sim.run

    val sim2: TurnSimulation[Person] = new TurnSimulation(net, TurnSim.stillHealthyLeftFunction(net)) with DepthFirstSelection[Person] with InfectedStateChange[Person]
    sim2.subscribe(new VirusVisualisation[Person](net))
    sim2.run
    println(net)

}